﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace masini
{
    class SedanPool :CarsFactory
    {
        static SedanPool _instance;
        List<SedanCar> cars;

        private SedanPool()
        {
            cars = new List<SedanCar>();
            cars.Add(new SedanCar("bmw", "alb", "manuala", "ac", "otto", "2m"));
            cars.Add(new SedanCar("audi", "alb", "manuala", "radio", "diesel", "2.3m"));
            cars.Add(new SedanCar("mercedes", "alb", "manuala", "proiectoare ceata", "diesel", "2.3m"));
        }

        public static SedanPool Instance()
        {
            if (_instance == null)
            {
                _instance = new SedanPool();
            }

            return _instance;
        }

        public override void Put(Car s)
        {
            if (s.GetType().ToString().Split('.')[1] == "SedanCar")
                cars.Add((SedanCar)s);
            else
                Console.WriteLine("Tipul masini nu corespunde cu pool-ul");
        }

        public override Car SearchByName(string name, bool sterge)
        {
            Car aux = new SedanCar();
            bool ok = false;
            foreach (Car c in cars)
            {
                if (c.getName() == name)
                {
                    aux = c;
                    ok = true;
                }
            }

            if (ok == true)
            {
                if (sterge)
                    cars.Remove((SedanCar)aux);
                return aux;
            }
            return new SedanCar();
        }
    }
}
